
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.JLabel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Patients.java
 *
 * Created on Aug 12, 2012, 4:17:44 AM
 */

/**
 *
 * @author ADM
 */
public class Patients extends javax.swing.JFrame {
ConnectDB conecttion = new ConnectDB();
    Connection conn = conecttion.Connect();
     int j=0;
    static  String mang[];
    /** Creates new form Patients */
    public Patients(String Name) {
        initComponents();
        GetInfoPatient(Name, lbID, lbName, lbType,lbAge, lbAdd, lbPhone, lbDoctor);
    }

   public void  GetInfoPatient(String Name,JLabel ID,JLabel jName,JLabel Type,JLabel Age,JLabel Add,JLabel Phone,JLabel Doctor) {
        try {

            CallableStatement call = conn.prepareCall("{call spPatientsInfo(?)}");
            call.setString(1, Name);
            ResultSet rs = call.executeQuery();
            ResultSetMetaData rsmd = rs.getMetaData();
            int NumOfCol = rsmd.getColumnCount();
            mang = new String[NumOfCol];
            for(int i=1;i<=NumOfCol;i++)
          {
              mang[j]=rsmd.getColumnName(i);
              j++;
          }
            while (rs.next()) {
                Vector v = new Vector();
                for (int i = 0; i <7; i++) {
                    v.addElement(rs.getString(mang[i]));
                }
                ID.setText((String) v.get(0));
                jName.setText((String) v.get(1));
                Type.setText((String) v.get(2));
                Age.setText((String) v.get(3));
                Add.setText((String) v.get(4));
                Phone.setText((String) v.get(5));
                Doctor.setText((String) v.get(6));
                if (v.get(4)==null) {
                    Phone.setText("Null");
                }


            }
             rs.close();
            call.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lbName = new javax.swing.JLabel();
        lbType = new javax.swing.JLabel();
        lbAdd = new javax.swing.JLabel();
        lbPhone = new javax.swing.JLabel();
        lbDoctor = new javax.swing.JLabel();
        lbID = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lbAge = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Customer Detail"));
        jPanel1.setPreferredSize(new java.awt.Dimension(484, 316));

        jLabel1.setText("Customer ID:");

        jLabel2.setText("Customer Name:");

        jLabel3.setText("Customer Type:");

        jLabel4.setText("Address:");

        jLabel5.setText("Phone:");

        jLabel7.setText("Doctor:");

        lbName.setText("jLabel9");

        lbType.setText("jLabel10");

        lbAdd.setText("jLabel11");

        lbPhone.setText("jLabel12");

        lbDoctor.setText("jLabel14");

        lbID.setText("jLabel6");

        jLabel6.setText("Age:");

        lbAge.setText("jLabel8");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(131, 131, 131)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbAge)
                    .addComponent(lbName)
                    .addComponent(lbType)
                    .addComponent(lbID)
                    .addComponent(lbPhone)
                    .addComponent(lbDoctor)
                    .addComponent(lbAdd))
                .addContainerGap(191, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lbID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lbType))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lbAge))
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lbAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbPhone)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbDoctor))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel7)))
                .addContainerGap(64, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-500)/2, (screenSize.height-353)/2, 500, 353);
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Patients(null).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbAdd;
    private javax.swing.JLabel lbAge;
    private javax.swing.JLabel lbDoctor;
    private javax.swing.JLabel lbID;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lbPhone;
    private javax.swing.JLabel lbType;
    // End of variables declaration//GEN-END:variables

}
